SDKS-4738: Migrate Legacy SDK To OIDC Client In Reactjs Davinci Sample App#92
SDKS-4738: Migrate Legacy SDK To OIDC Client In Reactjs Davinci Sample App#92SteinGabriel merged 1 commit intomainfrom
Conversation
cerebrl
left a comment
There was a problem hiding this comment.
A few comments after an initial review.
| forceRenew: true, | ||
| }); | ||
| const tokens = await oidcState.oidcClient.token.exchange(authCode, authState); | ||
| if (tokens && typeof tokens === 'object' && 'error' in tokens) { |
There was a problem hiding this comment.
Being that these OIDC methods always return an object type, do we need all of these chained conditionals? From a type perspective, only OauthTokens | TokenExchangeErrorResponse | GenericError can be returned, so tokens should be truthy and always an object. The question should be limited to just "does this object have an error property", yeah? Or, am I missing something?
There was a problem hiding this comment.
Yeah, I went extra defensive here since I wasn't really sure if tokens would always be returned as an object type. Thanks for clarifying this. I'll update it.
| const [user, setUser] = useState(null); | ||
| const [authCode, setAuthCode] = useState(null); | ||
| const [authState, setAuthState] = useState(null); | ||
| const [oidcState] = useContext(OidcContext); |
There was a problem hiding this comment.
We seem to have many different patterns with this oidc related context usage. We have the following:
const [oidcState] = useContext(OidcContext);const [{ oidcClient }] = useContext(OidcContext);const [state] = useContext(OidcContext);
I'd like to drop #3 as a pattern and just use #1 for accessing the state props, like username, etc., and use #2 for when we just want the oidcClient.
There was a problem hiding this comment.
For sure. Updated, thanks!
ancheetah
left a comment
There was a problem hiding this comment.
Migration looks good overall. Left some comments about removing try-catches and not throwing errors. Some other notes:
- Please update theming in every component, not just some. For example, icons. You can use AI to help.
- Please ensure CI passes. I can help teach you how to run e2e locally if you need help.
javascript/reactjs-todo-davinci/client/components/davinci-client/hooks/oauth.hook.js
Outdated
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/components/davinci-client/protect.js
Outdated
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/utilities/protect.api.js
Outdated
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/components/utilities/protect.utils.js
Outdated
Show resolved
Hide resolved
ancheetah
left a comment
There was a problem hiding this comment.
Review of Protect stuff
javascript/reactjs-todo-davinci/client/components/davinci-client/form.js
Outdated
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/components/utilities/protect.utils.js
Outdated
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/components/davinci-client/protect.js
Outdated
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/components/davinci-client/hooks/create-client.utils.js
Show resolved
Hide resolved
javascript/reactjs-todo-davinci/client/components/davinci-client/protect.js
Outdated
Show resolved
Hide resolved
ancheetah
left a comment
There was a problem hiding this comment.
Nice job. Approving now but before merging let's squash everything into one commit and wait till Justin gets back in case he has last minute feedback.
cerebrl
left a comment
There was a problem hiding this comment.
Looks great. Thanks, @SteinGabriel !!
fix: pass whole query params to signin link in header.js feat: replace HTTP client with plain fetch feat: add oidcClient and protectApi to global state docs: update README file refactor(reactjs-todo-davinci): refactor state menagement fix(reactjs-todo-davinci): update copyright date fix(reactjs-todo-davinci): fix list issues; update comments; fix code issues; fix(reactjs-todo-davinci): remove REALM_PATH constant fix(reactjs-todo-davinci): fix inconsistencies with pretect initialization fix(reactjs-todo-davinci): remove protect.api.js; update copyright message; fix(reactjs-todo-davinci): remove protect.api.js; update copyright message; fix(reactjs-todo-davinci): make initProtectApi more explicit; avoid throwing errors; fix(reactjs-todo-davinci): remove create-config; remove try/catch; fix(reactjs-todo-davinci): remove initProtectApi utility function fix(reactjs-todo-davinci): remove protectApi check in protect.js
62facf0 to
518947f
Compare
https://pingidentity.atlassian.net/browse/SDKS-4738
Description
Migrates React DaVinci Todo sample app from legacy SDK (
@forgerock/javascript-sdk) to OIDC Client (@forgerock/oidc-client), aligning with patterns established in React Journey sample app.Changes
New Files:
client/context/oidc.context.js- OIDC context provider managing client initialization and auth stateclient/context/protect.context.js- Protect API context provider (bootstrap mode)client/context/theme.context.js- Theme context provider (migrated from global-state)Deleted Files:
client/global-state.js- Removed AppContext in favor of dedicated context providersKey Modifications:
client/index.js- Bootstrap pattern with Init component and loading gate (matches react-journey)client/utilities/request.js- Replace HttpClient.request with native fetch + Bearer tokenclient/utilities/route.js- Validate routes using oidcClient.token.get() and oidcClient.user.info()client/components/davinci-client/hooks/oauth.hook.js- Token exchange via oidcClient.token.exchange()(previously
TokenManager.getTokens())client/components/layout/header.js- Pass all query params to login link (not just centralLogin/journey)package.json- Swap@forgerock/javascript-sdk→@forgerock/oidc-client